<?php
/**
 * Groups module for XOOPS
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code 
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       The Groups Project http://code.google.com/p/groupsforxoops/
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package         groups
 * @since           2.3.0
 * @author          Hui Xiao < xh.8326@gmail.com >
 * @version         $Id: column.php Sat Jul 18 13:16:40 CST 2009
 */

if ( !defined("XOOPS_ROOT_PATH") )  exit;
if ( !class_exists("xoGroups") ) {
	include dirname(dirname(__FILE__))."/include/groups.php";
}
class groupsColumn extends XoopsObject 
{
	public function __construct() {
		$this->initVar("column_id", XOBJ_DTYPE_INT, null, false); // 分类ID
		$this->initVar("group_id", XOBJ_DTYPE_INT); // 分类ID
		$this->initVar("column_name", XOBJ_DTYPE_TXTBOX, null, true); 
	}
}

class groupsColumnHandler extends XoopsPersistableObjectHandler
{
	public function __construct($db) {
        parent::__construct($db,"groups_column","groupsColumn","column_id");
    }
    
    /**
     * create and modify a column
     *
     * @param array $params
     * @return int $column_id
     */
    public function setColumn( array $params ) {
        $myts =  MyTextSanitizer::getInstance();
        if ( empty($params) || !is_array($params) ) return false;
    	$column_id = isset($params["column_id"]) ? intval($params["column_id"]) : 0 ;
        if ( !empty($column_id) ) {
            $obj = $this->get($column_id);
        } else {
            $obj = $this->get();
        }
    	foreach ( $params as $key => $val ) {
			if ( !isset($obj->vars[$key]) || $myts->stripSlashesGPC($val) == $obj->getVar($key) ) continue;
			$obj->setVar($key, $val);
		}
    	if ( $column_id = $this->insert($obj) ) {
    	    return $column_id;
    	}
    	return false;
    }
    
    /**
     * select column list
     *
     * @param array $params
     * @param bool $asObj
     * @return array $ret array/object array
     */
    public function getColumns( array $params, $asObj=true ) {
        $criteria = xoGroups::getCriteria($params);
        $fields = ( isset($params["fields"]) && is_array($params["fields"]) ) ? $params["fields"] : null ;
        $ret = $this->getAll($criteria, $fields, $asObj);
        return $ret;
    }
    
    /**
     * delete a column
     *
     * @param int $column_id
     * @return bool $ret
     */
    public function deleteColumn( $column_id ) {
        
    }
    
}